package com.zsrt.card.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zsrt.card.entity.CardEntity;

//@RequestMapping("/card")
@Controller
public class CardController{
	
	/**
	 * http://localhost:8088/jmj-springmvc-ch02/add?id=111&cardNumber=eeee
	 * @param entity   传来的参数自动封装成对象
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public CardEntity add(CardEntity entity){
		System.out.println(entity.toString());
		return entity;
	}
	
	/**
	 * http://localhost:8088/jmj-springmvc-ch02/add1
	 * postman 选取不同的方法  会进入不同的方法
	 * @param entity  
	 * @return
	 */
	@RequestMapping(value="/add1",method=RequestMethod.DELETE)
	public CardEntity add1(CardEntity entity){
		System.out.println(entity.toString());
		System.out.println("进入delete方法...");
		return entity;
	}
	@RequestMapping(value="/add1",method=RequestMethod.PUT)
	public CardEntity add2(CardEntity entity){
		System.out.println(entity.toString());
		System.out.println("进入put方法...");
		return entity;
	}
	@RequestMapping(value="/add1",method=RequestMethod.POST)
	public CardEntity add3(CardEntity entity){
		System.out.println(entity.toString());
		System.out.println("进入post方法...");
		return entity;
	}
	/**
	 * http://localhost:8088/jmj-springmvc-ch02/add4?id=33&username=www  √
	 * http://localhost:8088/jmj-springmvc-ch02/add4?id=33             √
	 * http://localhost:8088/jmj-springmvc-ch02/add4?username=www      ×
	 * http://localhost:8088/jmj-springmvc-ch02/add4?id=0&username=""
	 * CardEntity [id=0, bankId=0, cardNumber="", 
	 * 
	 * http://localhost:8088/jmj-springmvc-ch02/add4?id=0
	 * [id=0, bankId=0, cardNumber=null,
	 * @param idd    required=true 表示一定要有参数    形参      如果不传过来报400错误
	 * @param cardNumber
	 * @return
	 */
	@RequestMapping("/add4")
	public CardEntity add4(
			@RequestParam(value="id",required=true)  int idd,
			@RequestParam(value="username",required=false)String cardNumber){
		CardEntity entity= new CardEntity();
		entity.setId(idd);
		entity.setCardNumber(cardNumber);
		System.out.println(entity.toString());
		return entity;
	}

	
	
}
